package com.huitone.smspfm.oldclient.model;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.oldclient.app.AppStaticConfigs;
import com.huitone.smspfm.oldclient.logger.ExtLogger;

/**   
* @Title: RespSms.java 
* @Package com.unicom.gddw.dao.entity 
* @Description: 提交结果 
* @author ybliang   
* @date 2017年3月21日 下午4:15:33 
* @version V1.0   
*/
public class RespSms extends AbstractSms{
	
	private static final long serialVersionUID = 1L;
	
	private final static ExtLogger logger = ExtLogger.create(RespSms.class);
	
	//"<serialno>"+serialno+"</serialno><clientname>"+clientname+"</clientname><sendport>"+sendport+"</sendport>
	//<mobileno>"+mobileno+"</mobileno><sendtime>"+sendtime+"</sendtime><retcode>"+errorCode+"</retcode><retno>0</retno>
	//<newserialno>"+newSerialNo+"</newserialno><srvnode>"+srvNode+"</srvnode><servicecode>"+serviceCode+"</servicecode><errorcode>"+errorCode+"</errorcode><endl/>"
	
	public static Map<String,String> RESP_ELEMENTS = new HashMap<String,String>() {

		private static final long serialVersionUID = 1L;
		
		{
			put("serialno","<serialno>?</serialno>");
			put("clientname","<clientname>?</clientname>");
			put("sendport","<sendport>?</sendport>");
			put("mobileno","<mobileno>?</mobileno>");
			put("sendtime","<sendtime>?</sendtime>");
			put("retcode","<retcode>?</retcode>");
			put("retno", "<retno>?</retno>");
			put("newserialno", "<newserialno>?</newserialno>");
			put("srvnode", "<srvnode>?</srvnode>");
			put("servicecode", "<servicecode>?</servicecode>");
			put("errorcode", "<errorcode>?</errorcode>");
			put("endl", "<endl/>");
		}
		
	};
	
	public static Map<String,String> RESP_ELEMENTS_METHODS = new HashMap<String,String>() {

		private static final long serialVersionUID = 1L;
		
		{
			put("serialno","getSerialno");
			put("clientname","getClientname");
			put("sendport","getSendport");
			put("mobileno","getMobileno");
			put("sendtime","getSendtime");
			put("retcode","getRetcode");
			put("retno", "getRetno");
			put("newserialno", "getNewSerialNo");
			put("srvnode", "getSrvNode");
			put("servicecode", "getServiceCode");
			put("errorcode", "getErrorCode");
		}
		
	};
	
	private String sendtime;
	private String retcode;
	private String retno;
	
	private String newSerialNo;
	private String srvNode;
	private String serviceCode;
	
	private String errorCode;
	
	public String getSendtime() {
		return sendtime;
	}
	public void setSendtime(String sendtime) {
		this.sendtime = sendtime;
	}
	public String getRetcode() {
		return retcode;
	}
	public void setRetcode(String retcode) {
		this.retcode = retcode;
	}
	public String getRetno() {
		return retno;
	}
	public void setRetno(String retno) {
		this.retno = retno;
	}
	public String getNewSerialNo() {
		return newSerialNo;
	}
	public void setNewSerialNo(String newSerialNo) {
		this.newSerialNo = newSerialNo;
	}
	public String getSrvNode() {
		return srvNode;
	}
	public void setSrvNode(String srvNode) {
		this.srvNode = srvNode;
	}
	public String getServiceCode() {
		return serviceCode;
	}
	public void setServiceCode(String serviceCode) {
		this.serviceCode = serviceCode;
	}
	public String getErrorCode() {
		return errorCode;
	}
	public void setErrorCode(String errorCode) {
		setRetcode(errorCode);
		this.errorCode = errorCode;
	}
	
	@Override
	public String toString() {
		
		StringBuffer buffer = new StringBuffer();
		
		for (String element:AppStaticConfigs.rspRowElements) {
			
			try {
				
				if (StringUtils.equals("endl", element)) {
					buffer.append(RESP_ELEMENTS.get(element));
				} else {
					String name = RESP_ELEMENTS_METHODS.get(element);
					if (!StringUtils.isEmpty(name)) {
						Method method = this.getClass().getMethod(name, new Class[]{});
						try {
							buffer.append(StringUtils.replace(RESP_ELEMENTS.get(element), "?", StringUtils.toString(method.invoke(this, new Object[]{}))));
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						} catch (IllegalArgumentException e) {
							e.printStackTrace();
						} catch (InvocationTargetException e) {
							e.printStackTrace();
						}
					}
				}
			} catch (NoSuchMethodException e) {
				logger.error("不存在的响应消息文件元素:" + element, e);
			} catch (SecurityException e) {
				e.printStackTrace();
			}
		}
		
		return buffer.toString();
	}
	
}
